﻿using Caliburn.Micro;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Media;

namespace AdornerTest
{


	/// <summary>
	/// The object that is created when you add an item to the canvas
	/// I used JsonProperties to serialize the class for copy/paste
	/// </summary>
	public class SomeItem : PropertyChangedBase
	{
		private int _roundDecimalsTo = 0;

		public ObservableCollection<SomeContextMenuItem> ContextItems { get; set; }

		private bool _isSelected = false;

		/// <summary>
		/// When the object is selected, this gets set to true
		/// </summary>
		[JsonProperty("IsSelected")]
		public bool IsSelected
		{
			get { return _isSelected; }
			set
			{
				if (_isSelected != value)
				{
					_isSelected = value;
					this.NotifyOfPropertyChange(() => IsSelected);
				}
			}
		}

		private bool _isInput = false;
		[JsonProperty("IsInput")]
		public bool IsInput
		{
			get { return _isInput; }
			set
			{
				if (_isInput != value)
				{
					_isInput = value;
					this.NotifyOfPropertyChange(() => IsInput);
				}
			}
		}

		private bool _isOutput = false;
		[JsonProperty("IsOutput")]
		public bool IsOutput
		{
			get { return _isOutput; }
			set
			{
				if (_isOutput != value)
				{
					_isOutput = value;
					this.NotifyOfPropertyChange(() => IsOutput);
				}
			}
		}

		private SolidColorBrush _background = Brushes.White;
		[JsonProperty("Background")]
		public SolidColorBrush Background
		{
			get { return _background; }
			set
			{
				if (_background != value)
				{
					_background = value;
					this.NotifyOfPropertyChange(() => Background);
				}
			}
		}

		public Color BackgroundColor
		{
			get { return Background.Color; }
			set
			{
				Background = new SolidColorBrush(value);
				this.NotifyOfPropertyChange(() => BackgroundColor);
			}
		}


		private double _top = 0.0;
		[JsonProperty("Top")]
		public double Top
		{
			get { return _top; }
			set
			{
				if (_top != value)
				{
					if (value > 0)
					{
						_top = Math.Round(value, _roundDecimalsTo);
						this.NotifyOfPropertyChange(() => Top);
					}
				}
			}
		}
		private double _left = 0.0;
		[JsonProperty("Left")]
		public double Left
		{
			get { return _left; }
			set
			{
				if (_left != value)
				{
					if (value > 0)
					{
						_left = Math.Round(value, _roundDecimalsTo);

						this.NotifyOfPropertyChange(() => Left);
					}
				}
			}
		}

		private string _name = "";
		[JsonProperty("Name")]
		public string Name
		{
			get { return _name; }
			set
			{
				if (_name != value)
				{
					_name = value;
					this.NotifyOfPropertyChange(() => Name);
				}
			}
		}

		private double _width = 0.0;
		[JsonProperty("Width")]
		public double Width
		{
			get { return _width; }
			set
			{
				if (_width != value)
				{
					_width = Math.Round(value, _roundDecimalsTo);
					this.NotifyOfPropertyChange(() => Width);
				}
			}
		}

		private double _height = 0.0;
		[JsonProperty("Height")]
		public double Height
		{
			get { return _height; }
			set
			{
				if (_height != value)
				{
					_height = Math.Round(value, _roundDecimalsTo);
					this.NotifyOfPropertyChange(() => Height);
				}
			}
		}

		private double _fontSize = 16.0;
		[JsonProperty("FontSize")]
		public double FontSize
		{
			get { return _fontSize; }
			set
			{
				if (_fontSize != value)
				{
					_fontSize = value;
					this.NotifyOfPropertyChange(() => FontSize);
				}
			}
		}

		private FontFamily _font = new FontFamily("Arial");
		[JsonProperty("Font")]
		public FontFamily Font
		{
			get { return _font; }
			set
			{
				if (_font != value)
				{
					_font = value;
					this.NotifyOfPropertyChange(() => Font);
				}
			}
		}

		public SomeItem(double top, double left, double width, double height, string name, SolidColorBrush background)
		{
			Top = top;
			Left = left;
			Width = width;
			Height = height;
			this.Name = name;
			this.Background = background;
			this.ContextItems = new ObservableCollection<SomeContextMenuItem>();

			this.ContextItems.Add(new SomeContextMenuItem() { Name = "Cut", Action = ApplicationCommands.Cut });
			this.ContextItems.Add(new SomeContextMenuItem() { Name = "Copy", Action = new CopyItemCommand() });

		}




	}
}
